package com.group01.web.controller;

import com.group01.result.Result;
import com.group01.service.CollectService;
import com.group01.vo.Collect.CollectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.DecimalMin;
import java.util.List;

/**
 * @Description
 * @Author 翟玉龙
 * @Date 2024/6/23
 */
@RestController
@RequestMapping("/collect")
@Validated
@Api(tags = "收藏模块")
public class CollectController {
    /**
     * 注入
     */
    private final CollectService collectService;

    public CollectController(CollectService collectService) {
        this.collectService = collectService;
    }

    /**
     * 获取用户收藏信息
     * @return {@link Result }<{@link List }<{@link CollectVO }>>
     */
    @ApiOperation("获取用户收藏信息")
    @GetMapping
    public Result<List<CollectVO>> getCollectList() {
        return collectService.getCollectList();
    }

    /**
     * 删除与批量删除商品收藏
     * @param ids 商品收藏id集合
     * @return {@link Result }<{@link String }>
     */
    @ApiOperation("删除与批量删除商品收藏")
    @DeleteMapping
    public Result<String> deleteCollect(@RequestBody List<Integer> ids) {
        return collectService.deleteCollects(ids);
    }

    /**
     * 新增图书收藏
     * @param id 商品id
     * @return {@link Result }<{@link String }>
     */
    @ApiOperation("新增图书收藏")
    @PostMapping("/{id}")
    public Result<String> addCollect(@PathVariable @DecimalMin(value = "0" , message = "id为数字且大于0") Integer id) {
        return collectService.addCollect(id);
    }
}
